package com.song.boot;

import com.song.boot.applicationContextInitializer.ApplicationContextInitializerTest;
import com.song.boot.applicationListener.ApplicationEnvironmentPreparedEventTest;
import com.song.boot.applicationListener.ApplicationFailedEventTest;
import com.song.boot.applicationListener.ApplicationStartedEventTest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
public class BootApplication {

	public static void main(String[] args) {
		/**
		 * 自定义的
		 *
		 * 第一种方法
		 * 仿照Spring Boot初始化配置使用该接口实现类的方法，在项目的classpath下创建META-INF/spring.factories文件。并仿照Spring Boot的配置格式进行配置：
		 * # Application Context Initializers
		 * org.springframework.context.ApplicationContextInitializer=\
		 * com.secbro2.learn.initializer.LearnApplicationContextInitializer

		 * 第二种方法
		 * 通过application.properties或application.yml文件进行配置。格式如下：
		 * context.initializer.classes=com.secbro2.liearn.initializer.LearnApplicationContextInitializer
		 *
		 * 1
		 * 第三种方法 song-s 如下
		 * 通过SpringApplication提供的addInitializers方法进行追加配置的。
		 */

		SpringApplication app = new SpringApplication(BootApplication.class);

		app.addInitializers(new ApplicationContextInitializerTest());

		app.addListeners(new ApplicationEnvironmentPreparedEventTest());
		app.addListeners(new ApplicationFailedEventTest());
//		app.addListeners(new ApplicationPreparedEventTest());
		app.addListeners(new ApplicationStartedEventTest());

		app.run(args);
		System.out.println("4343");

		Map<String,String> maps = new HashMap<>();
		int a = 1 ;
		maps.put("1" ,"A1");
		maps.put("2" ,"A2");
		get1(maps , a);
		pr(maps,a);
	}


	private static void get1(Map<String,String> map  , int a){
		map.put("3" ,"A3");
		map.put("4" ,"A4");
		a = 33 ;
	}


	private static void pr(Map<String,String> map, int a){
		map.forEach((s, s2) -> System.out.println(s + "=="+s2));
		System.out.println(a);
	}
}
